import requests
import json


def get_tl_replay(word):
    url = 'http://www.tuling123.com/robot-chat/robot/chat/336055/AxRc'
    params = {
        "perception": {
            "inputText": {
                "text": word
            }
        },
        "userInfo": {
            "userId": "demo"
        }
    }
    headers = {
        "Content-Type": "application/json"
    }
    replay_text = ''
    try:
        resp = requests.post(url, data=json.dumps(params), headers=headers)
        resp_json = resp.json()
        replay_list = resp_json.get('data', dict()).get('results', list())
        if len(replay_list) > 0:
            replay_text = replay_list[0].get('values', dict()).get('text', '')
    except Exception:
        replay_text = ''
    return replay_text
